/* GUI CONVERTED from soivmta4.p (converter v1.76) Wed May 28 03:38:41 2003 */
/* soivmta4.p - PENDING INVOICE LINE ITEM MAINTENANCE                         */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.26 $                                                          */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.4      LAST MODIFIED: 10/20/94   BY: dpm *FR95*                */
/* REVISION: 7.4      LAST MODIFIED: 11/01/94   BY: ame *GN90*                */
/* REVISION: 7.4      LAST MODIFIED: 01/28/95   BY: ljm *H09Z*                */
/* REVISION: 8.5      LAST MODIFIED  03/06/95   BY: dpm *J044*                */
/* REVISION: 8.5      LAST MODIFIED  03/29/95   BY: dzn *F0PN*                */
/* REVISION: 8.5      LAST MODIFIED: 06/07/95   BY: DAH *J042*                */
/* REVISION: 8.5      LAST MODIFIED: 07/19/95   BY: DAH *J05N*                */
/* REVISION: 8.5      LAST MODIFIED: 04/29/96   BY: DAH *J0KJ*                */
/* REVISION: 8.5      LAST MODIFIED: 07/15/96   BY: ajw *J0Z6*                */
/* REVISION: 8.6      LAST MODIFIED: 10/22/96   BY: *K004* Kurt De Wit        */
/* REVISION: 8.6      LAST MODIFIED: 07/09/97   BY: *H0ZJ* Samir Bavkar       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* Annasaheb Rahane   */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 11/24/98   BY: *M017* Sandy Brown        */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/23/00   BY: *N0ND* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/25/00   BY: *L121* Gurudev Chennuru   */
/* REVISION: 9.1      LAST MODIFIED: 11/08/00   BY: *N0TN* Jean Miller        */
/* Revision: 1.19       BY: Katie Hilbert       DATE: 04/01/01 ECO: *P002*    */
/* Revision: 1.22     BY: Robin McCarthy        DATE: 11/08/02 ECO: *P0JS*    */
/* Revision: 1.23     BY: Amit Chaturvedi       DATE: 11/14/02 ECO: *N1ZN*    */
/* Revision: 1.25     BY: Laurene Sheridan      DATE: 11/24/02 ECO: *P09M*    */
/* $Revision: 1.26 $  BY: Rajesh Kini           DATE: 05/28/03 ECO: *P0TC*    */
/* $Revision: eb2 sp3 $   BY: Joy Huang       DATE: 11/03/03  ECO: *HK-S-015*    */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define shared variable line         like sod_line.
define shared variable del-yn       like mfc_logical.
define shared variable prev_due     like sod_due_date.
define shared variable prev_consume like sod_consume.
define shared variable prev_type    like sod_type.
define shared variable delete_line  like mfc_logical.
define shared variable prev_qty_ord like sod_qty_ord.
define shared variable sod_recno      as recid.
define shared variable so_recno       as recid.
define shared variable pcqty        like sod_qty_ord.
define shared variable ln_fmt       like soc_ln_fmt.
define shared variable so_db        like dc_name.
define shared variable err_stat       as integer.
define shared variable sonbr        like sod_nbr.
define shared variable soline       like sod_line.
define shared variable continue     like mfc_logical.
define shared variable clines         as integer initial ?.
define shared variable mult_slspsn  like mfc_logical no-undo.
define shared variable sodcmmts     like soc_lcmmts label "Comments".
define shared variable save_parent_list  like sod_list_pr.
define shared variable discount       as decimal label "Discount"
   format "->>>9.9<<<".
define shared variable reprice_dtl  like mfc_logical label "Reprice".

define variable err-flag              as integer  no-undo.
define variable desc1               like pt_desc1 no-undo.
define variable use-log-acctg         as logical  no-undo.

define shared frame c.
define shared frame d.

continue = no.

for first so_mstr
   fields(so_inv_nbr so_nbr so_prepaid)
   where recid(so_mstr) = so_recno
   no-lock:
end. /* FOR FIRST so_mstr */

for first sod_det
   where recid(sod_det) = sod_recno
   exclusive-lock:
end. /* FOR FIRST sod_det */

/* CHECK IF LOGISTICS ACCOUNTING IS ENABLED */
{gprun.i ""lactrl.p"" "(output use-log-acctg)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/*DEFINE FORMS C AND D*/
/*HK-S-015           {soivlnfm.i}*/
/*HK-S-015*/         {xxsoivlnfm.i}
/*V8:HiddenDownFrame=c */
view frame c.

if ln_fmt
then
   view frame d.

if sod_sched
   and (can-find (first sch_mstr where sch_type = 1
   and sch_nbr  = sod_nbr
   and sch_line = sod_line)
    or can-find (first sch_mstr where sch_type  = 2
   and sch_nbr  = sod_nbr
   and sch_line = sod_line)
    or can-find (first sch_mstr where sch_type  = 3
   and sch_nbr  = sod_nbr
   and sch_line = sod_line))
then do:

   /* CANNOT DELETE, SCHEDULE EXISTS */
   {pxmsg.i &MSGNUM=6022 &ERRORLEVEL=3}
   leave .
end. /* IF sod_sched... */

if sod_btb_type = "02"
   or sod_btb_type = "03"
then do:

   /* DELETE NOT ALLOWED */
   {pxmsg.i &MSGNUM=1021 &ERRORLEVEL=3}
   leave.
end. /* IF sod_btb_type = "02" ... */

/* DELETE LINE INFORMATION THAT MIGHT EXIST IN OTHER DATABASES */
for first si_mstr
   fields(si_cur_set si_db si_git_acct si_git_cc si_git_sub si_gl_set si_site)
   where si_site = sod_site
   no-lock:
end. /* FOR FIRST si_mstr */

if si_db <> so_db
then do:

   {gprun.i ""gpalias3.p"" "(si_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

   assign
      sonbr  = so_nbr
      soline = sod_line .

   /* ADDED INPUT PARAMETER no TO NOT EXECUTE MFSOFC01.I   */
   /* AND MFSOFC02.I WHEN CALLED FROM DETAIL LINE          */
   {gprun.i ""solndel.p"" "(input no)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* RESET THE DB ALIAS TO THE SALES ORDER DATABASE */
   {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

   sod_recno = recid(sod_det).
end. /* IF si_db <> so_db */

/*IF RMA RECEIPT LINE, NO NEED TO UPDATE ACCUM QTY TABLE OR pih_hist*/

/* UPDATE ACCUM QTY WORKFILE WITH REVERSAL.  save_parent_list
**          DETERMINED IN soivmtea.p */

if sod_fsm_type <> "RMA-RCT"
then do:

   /* CHANGED 3RD PARAMETER FROM sod_qty_ord TO prev__qty_ord AND 4TH */
   /* PARAMETER FROM (sod_qty_ord * save_parent_list) TO              */
   /* (prev_qty_ord * save_parent_list)                               */

   {gprun.i ""gppiqty2.p""
      "(sod_line,
        sod_part,
        - prev_qty_ord / sod_um_conv,
        - (prev_qty_ord  / sod_um_conv * save_parent_list),
        sod_um,
        yes,
        yes,
        yes
      )"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* DELETE SALES ORDER LINE RELATED PRICE LIST HISTORY */
   {gprun.i ""gppihdel.p""
      "( 1,
         sod_nbr,
         sod_line
      )"}
/*GUI*/ if global-beam-me-up then undo, leave.

end. /* IF sod_fsm_type <> "RMA-RCT" */

if can-find (first sob_det where sob_nbr = sod_nbr
   and sob_line = sod_line)
then do:

   if sod_type = ""
   then do:

      /* DELETE MRP PLANNED ORDER FOR PARENT */
      /* CHANGED PRE-PROCESSOR TO A TERM */
      {mfmrw.i "sod_fas"
               sod_part
               sod_nbr
               string(sod_line)
               """"
               ?
               sod_due_date
               "0"
               "SUPPLYF"
               PLANNED_F/A_ORDER
               sod_site}
   end. /* IF sod_type = "" */

   delete_line = yes.
   /* DELETE SOB, MRP etc. FOR COMPONENTS */
   {gprun.i ""sosomtk.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

end. /* IF CAN-FIND (FIRST sob_det WHERE sob_nbr = sod_nbr */

/* MRP WORKFILE */
/* CHANGED PRE-PROCESSOR TO A TERM */
{mfmrw.i
   "sod_det"
   sod_part
   sod_nbr
   string(sod_line)
   """"
   ?
   sod_due_date
   "0"
   "DEMAND"
   SALES_ORDER
   sod_site}

/*DELETE COMMENTS*/
for each cmt_det
   exclusive-lock
   where cmt_indx = sod_cmtindx:
   delete cmt_det.
end. /* FOR EACH cmt_det*/

find qad_wkfl
   where qad_key1  = "sod_sv_code"
   and   qad_key2  = sod_nbr + "+" + string(sod_line)
   no-error.
if available qad_wkfl
then
   delete qad_wkfl.

line = line - 1.

if sod_sched
then do:

   find scx_ref
      where scx_type  = 1
        and scx_order = sod_nbr
        and scx_line  = sod_line
      exclusive-lock.

   delete scx_ref.
end. /* IF sod_sched */

/* DELETE IMPORT EXPORT RECORDS */
for each ied_det
   exclusive-lock
   where ied_type = "1"
     and ied_nbr  = sod_nbr
     and ied_line = sod_line:

   delete ied_det.
end. /* FOR EACH ied_det */

/* DELETE TAX DETAIL RECORDS FOR THE SO DETAIL LINE TO BE DELETED */
for each tx2d_det
   exclusive-lock
   where tx2d_ref      = so_nbr
     and tx2d_nbr      = ""
     and tx2d_line     = sod_line
     and (tx2d_tr_type = "11"
      or tx2d_tr_type  = "12"
      or tx2d_tr_type  = "13"):

   delete tx2d_det.

end. /* FOR EACH tx2d_det */

for each tx2d_det
   exclusive-lock
   where tx2d_ref     = so_inv_nbr
     and tx2d_nbr     = so_nbr
     and tx2d_line    = sod_line
     and tx2d_tr_type = "16":

   delete tx2d_det.

end. /* FOR EACH tx2d_det */

/*DELETE THE SALES ORDER DETAIL RELATIONSHIPS FOR APM */
{gprun.i ""sosoapm4.p"" "(sod_nbr, sod_line)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/* IF LOGISTICS ACCOUNTING IS ENABLED */
if use-log-acctg
then do:

   /* LOGISTICS ACCTG CREATES ONLY TYPE 43 tx2d_det RECORDS FOR A PENDING     */
   /* INVOICE. PENDING INVOICES CAN NEVER BE DELETED BECAUSE THERE IS ALWAYS  */
   /* AN OUTSTANDING INVOICE QTY WHICH PREVENTS THE DELETION. ONLY SO LINES   */
   /* CREATED OUTSIDE PENDING INVOICE MAINTENANCE THAT HAVE NOT BEEN SHIPPED  */
   /* CAN BE DELETED IN THIS PROGRAM.                                         */

   /* DELETE LOGISTICS ACCOUNTING tx2d_det RECORDS FOR SALES ORDER LINE */
   {gprunmo.i &module = "LA" &program = "lataxdel.p"
              &param  = """(input '41',
                            input sod_nbr,
                            input sod_line)"""}
end. /* IF use-log-acctg */

for first qad_wkfl
where qad_key1 = string(sod_nbr,"x(8)") +
                 string(sod_line,"999") and
      qad_key2 = "CreditCard" exclusive-lock:
   /*
   * MUST UPDATE so_prepaid
   * IF A qad_wkfl
   * STILL EXISTS
   */
   so_prepaid = so_prepaid - qad_decfld[1].
   delete qad_wkfl.
end.


{gprun.i ""gpxrdlln.p"" "(input sod_nbr,
                          input sod_line,
                          input 'so')"}
/*GUI*/ if global-beam-me-up then undo, leave.


delete sod_det.

del-yn = no.
pause 0 .

clear frame c.

if ln_fmt
then
   clear frame d.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame d = F-d-title.

/* LINE ITEM DELETED */
{pxmsg.i &MSGNUM=6 &ERRORLEVEL=1}

continue = yes.
